-
Notifications
You must be signed in to change notification settings - Fork 7.6k
usb: device_next: new USB Video Class (UVC) implementation #76798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
usb: device_next: new USB Video Class (UVC) implementation #76798
Conversation
I am grateful for the work on the USB and Video stacks of Zephyr, as well as the entire Zephyr tree, on the shoulder of which this is built. |
Force push:
|
Force-push:
|
.dwMinBitRate = sys_cpu_to_le32(15360000), \ | ||
.dwMaxBitRate = sys_cpu_to_le32(15360000), \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these values coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are chosen arbitrarily, and I need to think about what should I do here: pick reasonable defaults? Deduce from other values? Let the user figure out by exposing a devicetree option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In future work, it will be possible to ask the sensor for VIDEO_CID_PIXEL_RATE
in combination with video_bits_per_pixel()
to generate this field.
.bLength = sizeof(struct usb_ep_descriptor), \ | ||
.bDescriptorType = USB_DESC_ENDPOINT, \ | ||
.bEndpointAddress = 0x81, \ | ||
.bmAttributes = USB_EP_TYPE_BULK, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe UVC can be BULK or ISO.... but I only see BULK supported here. Do you plan to have a way to select which type of EP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to mention that only BULK is supported through this early version. I will need to spend more time investigating the device_next
APIs for how ISO is implemented.
I cannot guarantee ETAs as I would do this feature on free time, but will add it to the roadmap: this will be needed at some point.
Very grateful for your reviews @XenuIsWatching I will force-push with the changes as soon as I get a chance to do so. |
Force-push:
|
182ac7c
to
cec26cc
Compare
02c1087
to
4bdc1ea
Compare
force push: rebased on |
force push: changed the way descriptors are declared and introduce video controls at the descriptor level (no support for controls commands yet) |
force push: implemented the UVC controls for the supported Video class controls. I did not test this yet with the samples, but on the internal fork, we could get an IMX219 sensor with exposure and gain control from the host, format selection at startup (but not runtime, see [1]). I believe that the last step for me is to test the sample on several boards that support |
Known limitations:[1]: there is currently no [2]: [3]: [4]: [5]: There are missing implementations for selector unit, extensions unit, encoding unit. TODO. [6]: [7]: [8]: [9]: [10]: Supports custom header size, but not passing custom header data yet. [11]: Still image capture (capturing one frame at full resolution) not supported. [12]: USB3CV compliance tests not all passing. TODO. [13]: Announcing different resolutions/FPS for different connection speed not supported. [14]: Asynchronous controls (the host setting a control, and a notification interrupt alert of completion) not supported. Supported features:[A]: Class API and enumeration [B]: [C]: [D]: [E]: Handling of control commands end-to-end from host to Zephyr video device [F]: Zephyr native Video API that allows to enqueue/dequeue frames like any other Zephyr video device. [G]: Supports fragmented frames as discussed in #66994 and #72827 [H]: [I]: Supports querying the min/max/current values of every controls end-to-end from host to Zephyr video driver. |
a7cd6cb
to
ea60ec0
Compare
I did not get USB/IP to work so far:
However, it could be detected on Linux to some extent:
|
I was too hasty, connected too many USB UVC devices to my host.
I see it on my side too. |
Force-push:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kartben please review
samples/subsys/usb/uvc/prj.conf
Outdated
CONFIG_LOG=y | ||
CONFIG_POLL=y | ||
CONFIG_VIDEO=y | ||
CONFIG_VIDEO_LOG_LEVEL_WRN=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not necessary here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, removed to let the default log level apply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very neat -- please check my comments, hopefully all pretty straightforward. Thanks!
force-push:
|
Introduce a new USB Video Class (UVC) implementation from scratch. It exposes a native Zephyr Video driver interface, allowing to call the video_enqueue()/video_dequeue() interface. It will query the attached video device to learn about the video capabilities, and use this to configure the USB descriptors. At runtime, this UVC implementation will send this device all the control requests, which it will send to the attached video device. The application can poll the format currently selected by the host, but will not be alerted when the host configures a new format, as there is no video.h API for it yet. Signed-off-by: Josuah Demangeon <me@josuah.net>
b860551
to
35a9324
Compare
samples/subsys/usb/uvc/README.rst
Outdated
@@ -0,0 +1,183 @@ | |||
.. zephyr:code-sample:: uvc | |||
:name: USB Video webcam | |||
:relevant-api: usbd_api video_interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to fix now (I mean it!) but in case there is another round of updates, just realized we now have a proper doxygen group for the UVC device api
:relevant-api: usbd_api video_interface | |
:relevant-api: usbd_api usbd_uvc video_interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I will aggregate all the non-blocking fixes to this branch then...
https://github.com/tinyvision-ai-inc/zephyr/pull/new/pr_fix_uvc
We still have all the non-video boards working without problem. For instance:
|
Following the addition of USB Video Class, this adds a sample that makes use of the zephyr,camera chosen node of any board to stream the video source to the host. A snippet video-sw-generator can be used to test and debug devices without a zephyr,camera chosen node. Signed-off-by: Josuah Demangeon <me@josuah.net>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josuah Thank you very much. This is a significant and valuable contribution to the USB device subsystem. Thank you also for your patience.
👍 The time spent waiting allowed to introduce UVC directly on top of the latest video and USB APIs, and testing it plenty. More on the roadmap! #76798 (comment) |
Dependencies:
drivers: video: introduce "GET" sub-operations #78603replaced by something else to comedrivers: video: allow allocation with a header preceding the buffer #79168not required anymorevideo: emul: virtual driver for an imager and RX engine #79482Downstream:
Build and run:
Documentation preview:
Try it on your own branch: